﻿@{Html.RenderPartial("FancyRequireScripts");}
<script>

    $(document).ready(function () {
        getallIlceAjax();

        $(".various").fancybox({
            maxWidth: 800,
            maxHeight: 600,
            fitToView: false,
            width: '70%',
            height: '70%',
            autoSize: false,
            closeClick: true,
            openEffect: 'elastic',
            closeEffect: 'fade',
            modal: true
        });
        $('#drpSehirler').change(function () {
            getallIlceAjax();
        });
    });
    function confirmDelete(ilceId) {
        if (confirm("Kaydı silmek istediğinizden emin misiniz?") == false)
            return;
        DeleteIlceAjax(ilceId);
    }
    function DeleteIlceAjax(ilceId)
    {
        $.ajax({
            url: '/Ilce/DeleteIlceAjax',
            data: {
                IlceId: ilceId
            },
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (data)
            {
                getallIlceAjax();
            }
        });
    }
    function getallIlceAjax() {

        SehirId = $('#drpSehirler').val();
        $("#createLink").attr('href', '/Ilce/Create?SehirId=' + SehirId);
        //$('#createLink').href = ;
        $.ajax({
            url: '/Ilce/GetAllIlcelerAjax',
            data: {
                IlId: SehirId
            },
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function (data) {
                //var mySelect = $('#drpMusteriler');
                var JSONData = eval(data);
                //mySelect.empty();
                $("#tblIlceler").children().remove();
                $('#tblIlceler').append('<thead><tr><th>Ad</th><th>Düzenle</th><th>Sil</th></tr></thead>');
                $.each(JSONData, function (index, itemData) {

                    $('#tblIlceler').append('<tr>' +
                        '<td>' + itemData.Ad + '</td>' +
                        '<td><a href="/Ilce/Duzenle/' + itemData.Id.toString() + '" class="various" data-fancybox-type="iframe">Düzenle</a></td>' +
                        '<td><a href="#" onclick="confirmDelete(' + itemData.Id.toString() + ')" >Sil</a></td>' +
                        '</tr>');
                    //mySelect.append($('<option></option>').val(itemData.Id).html(itemData.Ad));
                });
            }
        });
    }

</script>
<p>
</p>
<table>
     <tr>
        <td>@Html.DropDownList("drpIller", new SelectList(@ViewBag.SehirList, "Id", "Ad"), new { id = "drpSehirler" })</td>
        <td><a id="createLink" href='#' class='various' data-fancybox-type='iframe'>
            <img width="18" height="18" src="/Content/IconImages/plus.png" /></a></td>
    </tr>
</table>
<table id="tblIlceler" class="bordered">
   
</table>
